package com.huamao.niceman.scrollviewpager.triangleviewpagerindicator;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.huamao.niceman.scrollviewpager.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager mViewPager ;
    private FragmentPagerAdapter adapter ;
    private List<String> mTitle = Arrays.asList("赵无极","钱友忠","孙扯淡","赵无极","钱友忠","孙扯淡","钱友忠","孙扯淡");
    private List<VpSimpleFragment> mContent = new ArrayList<>() ;
    private  ViewPagerIndicator mIndicator ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initDatas();
    }

    private void initDatas() {
        mIndicator.setVisbleTabCount(4);
        mIndicator.setTabItemTitles(mTitle);
        for (String title:mTitle){
            VpSimpleFragment fragment = VpSimpleFragment.newInstance(title) ;
            mContent.add(fragment) ;
        }
        adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mContent.get(position);
            }

            @Override
            public int getCount() {
                return mContent.size();
            }
        };
        mViewPager.setAdapter(adapter);
        mIndicator.setViewPager(mViewPager,0);

    }

    private void initView() {
        mViewPager = (ViewPager) findViewById(R.id.viewpager) ;
        mIndicator = (ViewPagerIndicator) findViewById(R.id.indi);
    }
}
